package com.xtool.livewallpaper.local

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.xtool.livewallpaper.base.MainApplication
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.io.File

class LocalWallpaperViewModel: ViewModel() {
    var files = MutableLiveData<List<File>>()
    fun load() {
        viewModelScope.launch(Dispatchers.IO) {
            val dir = File("${MainApplication.gContext.filesDir.absolutePath}/wallpapers")
            files.postValue(dir.listFiles()?.toList()?: listOf())
        }
    }
}